package com.bxy.dzsc.controller;

import com.bxy.dzsc.domain.Messages;
import com.bxy.dzsc.domain.Users;
import com.bxy.dzsc.service.MessagesService;
import com.bxy.dzsc.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

@Controller
public class MessagesController {
    @Autowired
    private MessagesService service;
    @Autowired
    private UsersService usersService;
    //查看所有留言
    @RequestMapping("/advice")
    @ResponseBody
    public ModelAndView findall(Model model){
        List<Messages> findall = service.findall();
        model.addAttribute("saveMessage",findall);
        ModelAndView mv=new ModelAndView("index");
        return mv;
    }
//    //用户留言
//    @RequestMapping("/")
//    @ResponseBody
//    public String addmessage(HttpSession session,String message){
//        Users user = (Users) session.getAttribute("user");
//        Date date=new Date();
//        Messages messages=new Messages(user.getId(),user.getUsername(),message,date);
//        service.insertmessage(messages);
//        return null;
//    }
//    //管理员删除留言
//    @RequestMapping("/")
//    @ResponseBody
//    public String deletemessage(Integer id){
//        service.deletemessage(id);
//        return null;
//    }
}
